package com.atguigu.tingshu.album.api;

import com.atguigu.tingshu.album.config.MinioConstantProperties;
import com.atguigu.tingshu.album.service.FileUploadService;
import com.atguigu.tingshu.common.result.Result;
import io.minio.errors.*;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;

@Tag(name = "上传管理接口")
@RestController
@RequestMapping("api/album")
public class FileUploadApiController {

    @Autowired
    private MinioConstantProperties minioConstantProperties;

    @Autowired
    private FileUploadService fileUploadService;

    /**
     * @Operation(summary = "文件上传")
     * 文件上传的API接口
     */
    @Operation(summary = "文件上传")
    /**
     * @PostMapping("fileUpload")
     * 映射POST请求到fileUpload路径
     */
    @PostMapping("fileUpload")
    public Result<String> fileUpload(MultipartFile file) throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
        // 调用fileUploadService的fileUpload方法上传文件，并获取上传后的URL
        // fileUploadService.fileUpload(file)
        String url = fileUploadService.fileUpload(file);

        // 构造并返回上传成功的响应结果
        // Result.ok(url)
        return Result.ok(url);
    }



}
